<?php
class Prichannel extends Eloquent
{
    public static $timestamps = false;
    public static $table = 'prichannels';

    public function user()
    {
        return $this->belongs_to('User');
    }

    public function channel()
    {
        return $this->belongs_to('Channel');
    }

    public static function insertOrUpdate($data)
    {
        $old = static::where_user_id($data['user_id'])->where_weekday($data['weekday'])->first();
        if (is_null($old)) {
            return static::create($data);
        } else {
            foreach ($data as $key => $value)
            {
                $old->{$key} = $value;
            }

            $old->save();

            return $old;
        }
    }
}